package com.glorysoft.hlgdpda.ui.trackin.view

import android.os.Bundle
import com.glorysoft.hlgdpda.BR
import com.glorysoft.hlgdpda.R
import com.glorysoft.hlgdpda.base.BaseActivity
import com.glorysoft.hlgdpda.databinding.ActivityBatchTrackInBinding
import com.glorysoft.hlgdpda.ui.trackin.viewmodel.TrackInViewModel
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils
import kotlinx.android.synthetic.main.activity_batch_track_in.*

/**
 * FileName: BatchTrackInActivity
 * Author: XJH
 * Date: 2021/5/17 11:39
 * Description:
 * History:
 */
class BatchTrackInActivity : BaseActivity<TrackInViewModel, ActivityBatchTrackInBinding>() {
    override fun layoutId(): Int {
        return R.layout.activity_batch_track_in
    }

    override fun initVariableId(): Int {
        return BR.trackInViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        rvLotList.setEmptyView(lotEmptyView)
        setTitle("按工单进站")
        viewModel.lotItems.clear()
        setRightListener("提交"){
            viewModel.workTrackIn(etEqpWorkID.text.toString(),etLot.text.toString())
        }
    }

    override fun initData() {
        initEdit(etLot,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.searchWorkInfo(s,etEqpWorkID.text.toString())
            }
        })

        viewModel.defUI.callObserve.observe(this){
            when(it.type){
                0-> etLot.setText("")
                200 -> tvCount.text = viewModel.lotItems.size.toString()
                2 ->{
                    FreeApi_DialogUtils.getConfirmAndCancelDialog(this, "确认删除", "我再想想", "是否确认删除该批次信息？",
                        {
                            viewModel.deleteInfo("lot",it.item)
                        }) {}.show(supportFragmentManager,"DELETE_DIALOG")
                }
            }
        }

        viewModel.defUI.startActivity.observe(this){
            etLot.setText("")
            etEqpWorkID.setText("")
            tvCount.text = ""
        }
    }
}